<template>
  <div class="app-container">
    <el-form ref="queryForm" :model="queryParams" :inline="true" label-width="100px">
      <el-form-item label="业务手册名称" prop="title">
        <el-input v-model="queryParams.title" placeholder="请输入业务手册名称" clearable size="small" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="更新时间">
        <el-date-picker v-model="dateRange" size="small" style="width: 240px" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"/>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table stripe v-loading="loading" :data="guideList">
      <el-table-column label="业务手册名称" align="center" prop="title" />
      <el-table-column label="更新时间" align="center" prop="fileUpdateTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.fileUpdateTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="文件大小" align="center" prop="contentSize" />
      <el-table-column label="业务手册文件" align="center">
        <template slot-scope="scope">
          <span>{{ scope.row.fileName }}.{{ scope.row.contentType }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" v-hasPermi="['system:guide:edit']" @click="handlePreview(scope.row)">预览</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
  </div>
</template>

<script>
import {
  listGuide,
  getGuide,
  delGuide,
  addGuide,
  updateGuide,
  exportGuide
} from '@/api/businessStandardLibrary/guide/guide';

export default {
  name: 'Guide',
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 日期范围
      dateRange: [],
      // 业务指南表格数据
      guideList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        title: undefined,
        businessCategoryId: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询业务指南列表 */
    getList() {
      this.loading = true
      listGuide(this.addDateRange(this.queryParams, this.dateRange)).then(
        response => {
          this.guideList = response.rows
          this.total = response.total
          this.loading = false
        }
      )
    },
    // 取消
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getGuide(id).then(response => {
        this.form = response.data
        this.open = true
        this.title = '修改业务指南';
      })
    },
    handlePreview(row) {
      this.filePreview(row.fileName, row.storagePath)
    }
  }
}
</script>
